﻿using _00.Common;
using SimpleRPC;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace _02.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            IHello client = RpcClientFactory.GetClient<IHello>("127.0.0.1", 9900);
            var result = client.SayHello("中文消息内容");
            Console.WriteLine("result: {0}", result);

            RpcTest();

            Console.ReadLine();

            User user = client.GetUser(10);
            Console.WriteLine("User: {0},{1},{2}", user.Id, user.Name, user.Sex);

            Console.WriteLine("complete.");
            Console.ReadLine();
        }

        private static void RpcTest()
        {
            IHello client = RpcClientFactory.GetClient<IHello>("127.0.0.1", 9900);
            int count = 10000;
            Stopwatch watch = new Stopwatch();
            watch.Start();
            for (int i = 0; i < count; i++)
            {
                var result = client.SayHello("中文消息内容");
                if (i == count - 1)
                {
                    Console.WriteLine(result);
                }
            }
            watch.Stop();
            Console.WriteLine("time: {0:f2}ms/c", watch.ElapsedMilliseconds / (float)count);
        }
    }
}
